using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace TCC.Framework
{
    /// <summary>
    /// 本地化语言管理
    /// </summary>
    public class WordManager : BaseManager
    {
        private Languagel _languagel = Languagel.Chinese;

        /// <summary>
        /// 本地化语言切换事件
        /// </summary>
        private TAction _wordChangedEvent;

        /// <summary>
        /// 当前本地化语言
        /// </summary>
        public Languagel CurrentLanguagel
        {
            get => _languagel;
            set
            {
                _languagel = value;
                _wordChangedEvent?.Invoke();
            }
        }

        private LanguageDate _languageDate;

        public WordManager(LanguageDate languageDate) : base()
        {
            _languageDate = languageDate;
        }

        public override void OnInit()
        {
            base.OnInit();
        }

        public string GetWord(int id)
        {
           LanguageDate.Data data = _languageDate.datas.Find((i) => { return i.ID == id; });
            return data == null ? "" : data.GetFieldValue<string>(CurrentLanguagel.ToString());
        }

        public void AddWordChangedEvent(TAction action)
        {
            _wordChangedEvent += action;
        }

    }
}
